package com.java.comprehensive.arithmetic.leecode.easy;

import util.TreeNode;

/**
 * @program: comprehensive-service
 *
 * @description: 对称二叉树
 *
 * @author: 窦绍飞
 *
 * @create: 2021-11-30 15:49
 **/
public class LeetCode_101 {

	public static boolean isSymmetric(TreeNode root) {
		if (root == null) {
			return true;
		}
		return isMirror(root.left, root.right);
	}

	public static boolean isMirror(TreeNode left, TreeNode right) {
		if (left == null && right == null)
			return true;
		if (left == null || right == null)
			return false;
		if (left.val != right.val)
			return false;

		return isMirror(left.left, right.right) && isMirror(left.right, right.left);
	}


	public static void main(String[] args) {
		// [1,2,2,3,4,4,3]
		// TreeNode treeNode = new TreeNode(1, new TreeNode(2, null, new TreeNode(3,
		// null, null)), new TreeNode(2, null, new TreeNode(3, null, null)));
		// TreeNode treeNode = new TreeNode(1, new TreeNode(2, new TreeNode(4, null,
		// null), new TreeNode(3, null, null)), new TreeNode(2, new TreeNode(3, null,
		// null),new TreeNode(4, null, null)));
		TreeNode treeNode = new TreeNode(1, new TreeNode(2, new TreeNode(2, null, null), null), new TreeNode(2, new TreeNode(2, null, null), null));
		System.out.println(isSymmetric(treeNode));
	}
}
